home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Tools / ClassAct / Examples / Chooser / chooserexample.c < prev    next >
C/C++ Source or Header  |  1997-05-10  |  5KB  |  229 lines

  1. ;/* Chooser Example
  2. sc link chooserexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /**
  7.  **  ChoosserExample.c -- chooser class example.
  8.  **
  9.  **  This is a simple example testing some of the capabilities of the
  10.  **  chooser gadget class.
  11.  **
  12.  **  This opens a window with chooser gadget. We will usse ClassAct.lib's
  13.  **  ChooserLables() and FreeChooserLabels() utility functions to create the
  14.  **  item labels.
  15.  **
  16.  **/
  17.  
  18. /* system includes
  19.  */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #include <exec/types.h>
  25. #include <exec/memory.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/gadgetclass.h>
  28. #include <graphics/gfxbase.h>
  29. #include <graphics/text.h>
  30. #include <graphics/gfxmacros.h>
  31. #include <utility/tagitem.h>
  32. #include <workbench/startup.h>
  33. #include <workbench/workbench.h>
  34.  
  35. #include <proto/intuition.h>
  36. #include <proto/graphics.h>
  37. #include <proto/exec.h>
  38. #include <proto/dos.h>
  39. #include <proto/utility.h>
  40. #include <proto/wb.h>
  41. #include <proto/icon.h>
  42.  
  43. /* ClassAct includes
  44.  */
  45. #include <classact.h>
  46.  
  47. /* button option texts
  48.  */
  49. UBYTE *chooser[] =
  50. {
  51.     "1200",
  52.     "2400",
  53.     "4800",
  54.     "9600",
  55.     "19200",
  56.     "38400",
  57.     "57600",
  58.     "115200",
  59.     "230400",
  60.     NULL
  61. };
  62.  
  63. enum
  64. {
  65.     GID_MAIN=0,
  66.     GID_CHOOSER1,
  67.     GID_QUIT,
  68.     GID_LAST
  69. };
  70.  
  71. enum
  72. {
  73.     WID_MAIN=0,
  74.     WID_LAST
  75. };
  76.  
  77. enum
  78. {
  79.     OID_MAIN=0,
  80.     OID_LAST
  81. };
  82.  
  83. int main(void)
  84. {
  85.     struct MsgPort *AppPort;
  86.  
  87.     struct Window *windows[WID_LAST];
  88.  
  89.     struct Gadget *gadgets[GID_LAST];
  90.  
  91.     Object *objects[OID_LAST];
  92.  
  93.     struct List *chooserlist1;
  94.  
  95.     /* make sure our classes opened... */
  96.     if (!ButtonBase || !ChooserBase || !WindowBase || !LayoutBase)
  97.         return(30);
  98.     else if ( AppPort = CreateMsgPort() )
  99.     {
  100.         /* Create chooser label list.
  101.          */
  102.         chooserlist1 = ChooserLabels( "1200","2400","4800","9600","19200","38400","57600", NULL );
  103.  
  104.         if (chooserlist1)
  105.         {
  106.             /* Create the window object.
  107.              */
  108.             objects[OID_MAIN] = WindowObject,
  109.                 WA_ScreenTitle, "ClassAct Release 2.0",
  110.                 WA_Title, "ClassAct Chooser Example",
  111.                 WA_Activate, TRUE,
  112.                 WA_DepthGadget, TRUE,
  113.                 WA_DragBar, TRUE,
  114.                 WA_CloseGadget, TRUE,
  115.                 WA_SizeGadget, TRUE,
  116.                 WINDOW_IconifyGadget, TRUE,
  117.                 WINDOW_IconTitle, "Chooser",
  118.                 WINDOW_AppPort, AppPort,
  119.                 WINDOW_Position, WPOS_CENTERMOUSE,
  120.                 WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  121.                     LAYOUT_SpaceOuter, TRUE,
  122.                     LAYOUT_DeferLayout, TRUE,
  123.  
  124.                     LAYOUT_AddChild, gadgets[GID_CHOOSER1] = ChooserObject,
  125.                         GA_ID, GID_CHOOSER1,
  126.                         GA_RelVerify, TRUE,
  127.                         CHOOSER_Labels, chooserlist1,
  128.                         CHOOSER_Selected, 0,
  129.                     ChooserEnd,
  130.                     CHILD_NominalSize, TRUE,
  131.                     CHILD_Label, LabelObject, LABEL_Text, "_Baud Rate", LabelEnd,
  132.  
  133.                     LAYOUT_AddChild, ButtonObject,
  134.                         GA_ID, GID_QUIT,
  135.                         GA_RelVerify, TRUE,
  136.                         GA_Text,"_Quit",
  137.                     ButtonEnd,
  138.                     CHILD_WeightedHeight, 0,
  139.  
  140.                 EndGroup,
  141.             EndWindow;
  142.  
  143.               /*  Object creation sucessful?
  144.                */
  145.             if (objects[OID_MAIN])
  146.             {
  147.                 /*  Open the window.
  148.                  */
  149.                 if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  150.                 {
  151.                     ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  152.                     ULONG done = FALSE;
  153.                     ULONG result;
  154.                     UWORD code;
  155.  
  156.                      /* Obtain the window wait signal mask.
  157.                      */
  158.                     GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  159.  
  160.                     /* Input Event Loop
  161.                      */
  162.                     while (!done)
  163.                     {
  164.                         wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  165.  
  166.                         if ( wait & SIGBREAKF_CTRL_C )
  167.                         {
  168.                             done = TRUE;
  169.                         }
  170.                         else
  171.                         {
  172.                             while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  173.                             {
  174.                                 switch (result & WMHI_CLASSMASK)
  175.                                 {
  176.                                     case WMHI_CLOSEWINDOW:
  177.                                         windows[WID_MAIN] = NULL;
  178.                                         done = TRUE;
  179.                                         break;
  180.  
  181.                                     case WMHI_GADGETUP:
  182.                                         switch (result & WMHI_GADGETMASK)
  183.                                         {
  184.                                             case GID_QUIT:
  185.                                                 done = TRUE;
  186.                                                 break;
  187.                                         }
  188.                                         break;
  189.  
  190.                                     case WMHI_ICONIFY:
  191.                                         CA_Iconify(objects[OID_MAIN]);
  192.                                         windows[WID_MAIN] = NULL;
  193.                                         break;
  194.  
  195.                                     case WMHI_UNICONIFY:
  196.                                         windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  197.  
  198.                                         if (windows[WID_MAIN])
  199.                                         {
  200.                                             GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  201.                                         }
  202.                                         else
  203.                                         {
  204.                                             done = TRUE;    // error re-opening window!
  205.                                         }
  206.                                          break;
  207.                                 }
  208.                             }
  209.                         }
  210.                     }
  211.                 }
  212.  
  213.                 /* Disposing of the window object will also close the window if it is
  214.                  * already opened, and it will dispose of the layout object attached to it.
  215.                  */
  216.                 DisposeObject(objects[OID_MAIN]);
  217.             }
  218.  
  219.             /* free the chooser list
  220.              */
  221.             FreeChooserLabels(chooserlist1);
  222.         }
  223.  
  224.         DeleteMsgPort(AppPort);
  225.     }
  226.  
  227.     return(0);
  228. }
  229.